package routes

import (
	"net/http"
	"production-tracker/handlers"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

// RegisterRoutes 注册所有路由
func RegisterRoutes(router *gin.Engine, db *gorm.DB) {
	// 创建处理器
	h := handlers.NewHandler(db)

	// API路由组
	api := router.Group("/api/v1")
	{
		// 健康检查
		api.GET("/health", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{"status": "ok"})
		})

		// 工作进度计划
		api.GET("/work-plans", h.GetWorkPlans)
		api.GET("/work-plans/:id", h.GetWorkPlan)
		api.POST("/work-plans", h.CreateWorkPlan)
		api.PUT("/work-plans/:id", h.UpdateWorkPlan)
		api.DELETE("/work-plans/:id", h.DeleteWorkPlan)

		// 物料外发清单
		api.GET("/materials", h.GetMaterials)
		api.GET("/materials/:id", h.GetMaterial)
		api.POST("/materials", h.CreateMaterial)
		api.PUT("/materials/:id", h.UpdateMaterial)
		api.DELETE("/materials/:id", h.DeleteMaterial)

		// 数据查询
		api.GET("/work-order-data", h.GetWorkOrderData)
		api.GET("/work-order-data/:id", h.GetWorkOrderDatum)
		api.POST("/work-order-data", h.CreateWorkOrderDatum)
		api.PUT("/work-order-data/:id", h.UpdateWorkOrderDatum)
		api.DELETE("/work-order-data/:id", h.DeleteWorkOrderDatum)

		// 钢网追踪
		api.GET("/stencils", h.GetStencils)
		api.GET("/stencils/:id", h.GetStencil)
		api.POST("/stencils", h.CreateStencil)
		api.PUT("/stencils/:id", h.UpdateStencil)
		api.DELETE("/stencils/:id", h.DeleteStencil)

		// 治具追踪
		api.GET("/fixtures", h.GetFixtures)
		api.GET("/fixtures/:id", h.GetFixture)
		api.POST("/fixtures", h.CreateFixture)
		api.PUT("/fixtures/:id", h.UpdateFixture)
		api.DELETE("/fixtures/:id", h.DeleteFixture)

		// SOP签核追踪
		api.GET("/sop-approvals", h.GetSOPApprovals)
		api.GET("/sop-approvals/:id", h.GetSOPApproval)
		api.POST("/sop-approvals", h.CreateSOPApproval)
		api.PUT("/sop-approvals/:id", h.UpdateSOPApproval)
		api.DELETE("/sop-approvals/:id", h.DeleteSOPApproval)

		// 批量操作
		api.POST("/bulk/export", h.ExportData)
		api.POST("/bulk/import", h.ImportData)
	}
}
